package com.neural.neighbourhood;

import java.util.ArrayList;
import java.util.List;

import com.neural.descriptor.Point;
import com.neural.descriptor.SizeDescriptor;

public class DiagonalNeighbourhood extends Neighbourhood {

	public DiagonalNeighbourhood() {
		super("diagonal");
	}

	@Override
	public List<Point> getPointsFor(Point point, SizeDescriptor size, Integer neighbourSize) {

		List<Point> points = new ArrayList<Point>(neighbourSize * 4);
		for (int i = 1; i <= neighbourSize; i++) {
			if (point.getXPos() - i >= 0 && point.getYPos() - i >= 0) {
				points.add(new Point(point.getXPos() - i, point.getYPos() - i));
			}
			if (point.getXPos() - i >= 0 && point.getYPos() + i <= size.getSizeY() - 1) {
				points.add(new Point(point.getXPos() - i, point.getYPos() + i));
			}
			if (point.getXPos() + i <= size.getSizeX() - 1 && point.getYPos() - i >= 0) {
				points.add(new Point(point.getXPos() + i, point.getYPos() - i));
			}
			if (point.getXPos() + i <= size.getSizeX() - 1 && point.getYPos() + i <= size.getSizeY() - 1) {
				points.add(new Point(point.getXPos() + i, point.getYPos() + i));
			}
		}

		return points;
	}
}
